package com.jm.product.provider.core;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.java.framework.common.pagination.OrderBy;
import com.java.framework.common.pagination.Pager;
import com.java.framework.common.pagination.SearchBean;
import com.java.framework.entity.IdEntity;
import com.java.framework.persistence.BaseDAO;
import com.java.framework.service.impl.BaseServiceImpl;

public class BaseService<T extends IdEntity<PK>, PK extends Serializable> extends BaseServiceImpl<T, PK> {
	
	@Autowired
	protected BaseDAO<T, PK> dao;
	
	public BaseService() {
		// TODO Auto-generated constructor stub
	}
	
	public T getById(PK id) {
	    return dao.get(id);
	  }
/*
	  public T getLockById(PK id) {
	    return dao.getLock(id);
	  }
*/
	  @Transactional(readOnly = false)
	  public T save(T t) {
	    return dao.save(t);
	  }

	  @Transactional(readOnly = false)
	  public T saveOrUpdate(T t) {
	    return dao.save(t);
	  }

	  public boolean exists(PK id) {
	    return dao.exists(id);
	  }

	  @Transactional(readOnly = false)
	  public void remove(T object) {
	    dao.remove(object);
	  }

	  /**
	   * Generic method to delete an object based on class and id
	   * 
	   * @param id the identifier (primary key) of the object to remove
	   */
	  @Transactional(readOnly = false)
	  public void removeById(PK id) {
	    dao.remove(id);
	  }

	  public Pager<T> getPager(List<SearchBean> searchBeans, List<OrderBy> orderBys, int currentPage,
	      int pageSize) {
	    return dao.getPager(searchBeans, orderBys, currentPage, pageSize);
	  }

	  public List<T> list(List<SearchBean> searchBeans, List<OrderBy> orderBys, int startNum,
	      int endNum) {
	    List<T> results = dao.list(searchBeans, orderBys, startNum, endNum);
	    return results;
	  }
}
